package logic

import (
	"context"
	"user_srv/internal/dao"
	"user_srv/internal/svc"
	"user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetSignListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetSignListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSignListLogic {
	return &GetSignListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetSignListLogic) GetSignList(in *user.GetSignListRequest) (*user.GetSignListResponse, error) {
	list, total, err := dao.GetSignList(in.UserId, in.Page, in.PageSize)
	if err != nil {
		return nil, err
	}

	var items []*user.SignRecordItem
	for _, v := range list {
		items = append(items, &user.SignRecordItem{
			Id:        int64(v.Id),
			UserId:    int64(v.UserId),
			SignDate:  v.SignDate.Format("2006-01-02"),
			Points:    uint32(v.Points),
			CreatedAt: v.CreatedAt.Format("2006-01-02 15:04:05"),
		})
	}

	return &user.GetSignListResponse{
		List:  items,
		Total: total,
	}, nil
}
